﻿Type=Activity
Version=2.71
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim V_XM As String
	Dim V_XB As String
	Dim V_NL As String
	Dim V_CH As String
	Dim V_BHID As Int
	Dim V_RYRQ As Int
	Dim V_RQ As Int
	
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim tbhMain As TabHost
	Dim btnOK As Button
	Dim btnSearch As Button
	Dim btnCancel As Button
	Dim scvTW As ScrollView
	Dim scvXY As ScrollView
	Dim scvQT As ScrollView
	Dim tbmManager As TabHostExtras
	Dim pnlAction As Panel
	Dim pnlTWH As Panel
	Dim pnlTW As Panel
	Dim pnlXY As Panel
	Dim pnlQT As Panel

	Dim TWLXList As List
	Dim TWSJList As List
	
	Dim FontSizeSM,FontSizeNR As Float
	Dim FontColorSM,FontColorNR As Int
	Dim EditTextHeight As Int
	
	FontSizeSM = 20
	FontSizeNR = 20
	
	FontColorSM = Colors.White
	FontColorNR = Colors.Red	
	
	EditTextHeight = PublicVar.GV_EditText_Height
	
	TWLXList.Initialize
	TWLXList.Clear
	TWLXList.Add("口表")
	TWLXList.Add("腋表")
	TWLXList.Add("肛表")
	
	TWSJList.Initialize
	TWSJList.Clear
	TWSJList.Add("2")
	TWSJList.Add("6")	
	TWSJList.Add("10")	
	TWSJList.Add("2")
	TWSJList.Add("6")	
	TWSJList.Add("10")		
	
	
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHTWDEdit")

	InitLayOut
End Sub

Sub Activity_Resume
	RefreshData
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub InitLayOut	
	tbhMain.AddTab("体温\脉搏\呼吸","formbhtwdedit1.bal")  '体温\脉搏\呼吸
	tbhMain.AddTab("出入量\血压","formbhtwdedit2.bal")  '出入量\血压
	tbhMain.AddTab("其他","formbhtwdedit3.bal")  '其他
	
	tbmManager.setTabTextSize(tbhMain, PublicVar.GV_HostTab_TextSize)
	tbmManager.setTabHostPadding(tbhMain, 0, 0, 0, 0)
	tbmManager.setTabContentViewPadding(tbhMain, 0, 0, 0, 0)
	tbmManager.setTabHeight(tbhMain, 60)
	
	SetViewsLayOut
	SetTWViewLayOut
	SetXYViewLayOut
	SetQTViewLayOut
	
	'高级菜单
	Activity.AddMenuItem("手工定位","MenuItemAdv")
	
	Activity.AddMenuItem("登陆科室","MenuItemAdv")
End Sub

Private Sub SetViewsLayOut
	pnlAction.Top = 100%Y -pnlAction.Height
	pnlAction.Left = 0
	pnlAction.Width = 100%X

	tbhMain.Top = 0
	tbhMain.Left = 0
	tbhMain.Height = pnlAction.Top
	tbhMain.Width = 100%X

	btnOK.Top = 0
	btnOK.Left = 0
	btnOK.Height = pnlAction.Height
	btnOK.Width = 33.33%X

	btnSearch.Top = 0
	btnSearch.Left = 33.33%X
	btnSearch.Height = pnlAction.Height
	btnSearch.Width = 33.33%X

	btnCancel.Top = 0
	btnCancel.Left = 66.66%X
	btnCancel.Height = pnlAction.Height
	btnCancel.Width = 33.33%X
	
	pnlTWH.Top =0
	pnlTWH.Left =0
	pnlTWH.Width = 100%X
	
	scvTW.Top = pnlTWH.Height
	scvTW.Left =0
	scvTW.Height = 100%Y - pnlTWH.Height
	scvTW.Width = 100%X
	
	scvXY.Top =0
	scvXY.Left =0
	scvXY.Height = 100%Y
	scvXY.Width = 100%X
End Sub

'体温脉搏呼吸布局
Private Sub SetTWViewLayOut
	Dim iLeft1,iLeft2,iLeft3,iLeft4,iLeft5,iTop1,iHeight As Int
	Dim iColor As Int	
	
	pnlTW = scvTW.Panel
	pnlTW.Height = 0
	
	iHeight = EditTextHeight
	iTop1 = 5
	iLeft1 = 0
	iLeft2 = 15%X
	iLeft3 = 35%X
	iLeft4 = 55%X
	iLeft5 = 75%X
	
	AddTWSMLabel("时间","SJ",iLeft1,iTop1,iLeft2 - iLeft1,iHeight)
	AddTWSMLabel("类型","TWLX",iLeft2,iTop1,iLeft3 - iLeft2,iHeight)	
	AddTWSMLabel("体温","TW",iLeft3,iTop1,iLeft4 - iLeft3,iHeight)	
	AddTWSMLabel("脉搏","MB",iLeft4,iTop1,iLeft5 - iLeft4,iHeight)
	AddTWSMLabel("呼吸","HX",iLeft5,iTop1,100%X - iLeft5,iHeight)	
	
	Dim sSJ,sTWLX As String
	Dim iRow As Int
	
	For i = 1 To 6 
		Select i
			Case 1,2,6 
				iColor = Colors.Red
			Case 3,4,5
				iColor = Colors.White
		End Select
		
		iRow = i-1
		sSJ = TWSJList.get(iRow)
		sTWLX = TWLXList.get(1)
		
		AddTWNR(sSJ,"SJ",iLeft1,iTop1+iHeight*iRow,iLeft2 - iLeft1,iHeight,iColor,Gravity.CENTER,1,i)
		AddTWNR(sTWLX,"TWLX",iLeft2,iTop1+iHeight*iRow,iLeft3 - iLeft2,iHeight,iColor,Gravity.LEFT,2,i)
		AddTWNR("","TW",iLeft3,iTop1+iHeight*iRow,iLeft4 - iLeft3,iHeight,iColor,Gravity.LEFT + Gravity.BOTTOM,3,i)
		AddTWNR("","MB",iLeft4,iTop1+iHeight*iRow,iLeft5 - iLeft4,iHeight,iColor,Gravity.LEFT + Gravity.BOTTOM,3,i)
		AddTWNR("","HX",iLeft5,iTop1+iHeight*iRow,100%X - iLeft5,iHeight,iColor,Gravity.LEFT + Gravity.BOTTOM,3,i)
	Next
	
	pnlTW.Height = iTop1 + iHeight * 15
End Sub

'出入量血压布局
Private Sub SetXYViewLayOut
	Dim iLeft1,iLeft2,iLeft3,iLeft4,iLeft5,iTop1,iHeight As Int
	Dim iColor As Int	
	
	pnlXY = scvXY.Panel
	pnlXY.Height = 0
	
	iTop1 = 5
	iHeight = EditTextHeight
	iLeft1 = 0
	iLeft2 = 35%X
	iLeft3 = 70%X	
	iColor = Colors.White
	
	AddXYNR("血压1","XY11",iLeft2,iTop1,iLeft2-iLeft1 - FontSizeNR,iHeight,iColor,Gravity.LEFT,0)
	AddXYNR("血压2","XY21",iLeft2,iTop1+iHeight*1,iLeft2-iLeft1 - FontSizeNR,iHeight,iColor,Gravity.LEFT,0)
	AddXYNR("/","XY12",iLeft3,iTop1,iLeft2-iLeft1 -FontSizeNR,iHeight,iColor,Gravity.LEFT,0)
	AddXYNR("/","XY22",iLeft3,iTop1+iHeight,iLeft2-iLeft1 - FontSizeNR,iHeight,iColor,Gravity.LEFT,0)
	AddXYNR("输入液量ml","SRYL",iLeft2,iTop1+iHeight*2,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,1)
	AddXYNR("大便(次)","DBCS",iLeft2,iTop1+iHeight*3,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,0)
	AddXYNR("尿量ml","NL",iLeft2,iTop1+iHeight*4,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,1)
	AddXYNR("其他排出","PCLQT",iLeft2,iTop1+iHeight*5,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,2)
	
	pnlXY.Height = iTop1 + iHeight * 6
	
End Sub

'其他布局
Private Sub SetQTViewLayOut
	Dim iLeft1,iLeft2,iLeft3,iLeft4,iLeft5,iTop1,iHeight As Int
	Dim iColor As Int	
	
	pnlQT = scvQT.Panel
	pnlQT.Height = 0
	
	iTop1 = 5
	iHeight = EditTextHeight
	iLeft1 = 0
	iLeft2 = 35%X
	iLeft3 = 70%X	
	iColor = Colors.White
	
	AddQTNR("身高cm","SG",iLeft2,iTop1+iHeight*0,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,1)
	AddQTNR("体重kg","TZ",iLeft2,iTop1+iHeight*1,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,0)
	AddQTNR("皮试","PS",iLeft2,iTop1+iHeight*2,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,1)
	AddQTNR("术后天数","CHRQ",iLeft2,iTop1+iHeight*3,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,2)
	AddQTNR("其他","QT",iLeft2,iTop1+iHeight*4,iLeft3-iLeft1,iHeight,iColor,Gravity.LEFT,2)
	
	pnlQT.Height = iTop1 + iHeight * 6
	
End Sub

Sub RefreshData
	Dim sRQ As String
	DateTime.DateFormat = "yyyy-MM-dd"  '月是M，大写
	sRQ = DateTime.Date(DateTime.Now)
	Activity.Title = "体征测量-" & V_CH & " " &V_XM & "(" & sRQ &")" 
	
	V_RQ = PublicVar.BRQ2DRQ(DateTime.Now)
	Refresh(V_RQ)
End Sub

Private Sub AddTWSMLabel(AText As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int)
	Dim lblSM As Label

	lblSM.Initialize("lblTWSM")
	lblSM.Text = AText
	lblSM.Gravity = Gravity.CENTER + Gravity.CENTER_VERTICAL
	lblSM.TextSize = FontSizeSM
	'lblSM.Color = FontColorSM
	lblSM.TextColor = FontColorSM
	lblSM.Tag = 0
	
	pnlTWH.AddView(lblSM,ALeft,ATop,AWidth,AHeight)
End Sub

Private Sub AddTWNR(AText As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int, _ 
	AColor As Int,AGravity As Int,ALX As Int,AXH As Int)
	Dim mapTag As Map
	mapTag.Initialize
	mapTag.Put("Field",AField)
	mapTag.Put("XH",AXH)
	
	Select ALX
		Case 1
			Dim lblSM As Label
			lblSM.Initialize("lblTWNR")
			lblSM.Text = AText
			lblSM.Gravity = AGravity
			lblSM.TextSize = FontSizeNR
			lblSM.Color = Colors.Black
			lblSM.TextColor = AColor
			lblSM.Tag = mapTag
			
			pnlTW.AddView(lblSM,ALeft,ATop,AWidth,AHeight)
		Case 2
			Dim btnNR As Button
			btnNR.Initialize("btnTWNR")
			btnNR.Text = AText
			btnNR.Gravity = AGravity
			btnNR.TextSize = FontSizeNR
			btnNR.Color = Colors.Black
			btnNR.TextColor = AColor
			btnNR.Tag = mapTag	
			
			pnlTW.AddView(btnNR,ALeft,ATop,AWidth,AHeight)
		Case 3
			Dim edtNR As EditText
			edtNR.Initialize("edtTWNR")
			edtNR.Text = AText
			edtNR.Hint = "--"
			edtNR.Gravity = AGravity
			edtNR.TextSize = FontSizeNR
			edtNR.Color = Colors.Black
			edtNR.TextColor = AColor
			edtNR.InputType = edtNR.INPUT_TYPE_DECIMAL_NUMBERS
			edtNR.Tag = mapTag				
	
			pnlTW.AddView(edtNR,ALeft,ATop,AWidth,AHeight)
		Case 4
			Dim chbNR As CheckBox
			chbNR.Initialize("chbTWNR")
			chbNR.Gravity = AGravity
			chbNR.Color = Colors.Black
			chbNR.TextColor = AColor
			chbNR.Checked = False
			chbNR.Tag = mapTag				
	
			pnlTW.AddView(chbNR,ALeft,ATop,AWidth,AHeight)				
	End Select

End Sub

Private Sub AddXYNR(ALabel As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int, _ 
	AColor As Int,AGravity As Int,ALX As Int)
	
	Dim iLblWidth,iLblLeftL As Int 
	
	Select ALabel.Length
		Case 1 
			iLblWidth = FontSizeNR
			iLblLeftL = ALeft - iLblWidth
		Case Else
			iLblWidth = ALeft
			iLblLeftL = 0
	End Select
	
	Dim lblSM As Label
	lblSM.Initialize("lblXYSM")
	lblSM.Text = ALabel
	lblSM.Gravity = Gravity.RIGHT + Gravity.CENTER_VERTICAL
	lblSM.TextSize = FontSizeSM
	'lblSM.Color = FontColorSM
	lblSM.TextColor = FontColorSM
	lblSM.Tag = AField
	
	pnlXY.AddView(lblSM,iLblLeftL,ATop,iLblWidth,AHeight)
	
	Dim edtNR As EditText
	edtNR.Initialize("edtXYNR")
	edtNR.Text = ""
	edtNR.Hint = "--"
	edtNR.Gravity = AGravity
	edtNR.TextSize = FontSizeNR
	edtNR.Color = Colors.Black
	edtNR.TextColor = AColor
	
	edtNR.Tag = AField				

	Select ALX
		Case 0  '数字
			edtNR.InputType = edtNR.INPUT_TYPE_NUMBERS	
		Case 1  '数字
			edtNR.InputType = edtNR.INPUT_TYPE_DECIMAL_NUMBERS
		Case 2  '文字
			edtNR.InputType = edtNR.INPUT_TYPE_TEXT
			
	End Select

	pnlXY.AddView(edtNR,ALeft,ATop,AWidth,AHeight)	
	

End Sub

Private Sub AddQTNR(ALabel As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int, _ 
	AColor As Int,AGravity As Int,ALX As Int)
	Dim iLblWidth,iLblLeftL As Int 
	
	Select ALabel.Length
		Case 1 
			iLblWidth = FontSizeNR
			iLblLeftL = ALeft - iLblWidth
		Case Else
			iLblWidth = ALeft
			iLblLeftL = 0
	End Select
	
	Dim lblSM As Label
	lblSM.Initialize("lblQTSM")
	lblSM.Text = ALabel
	lblSM.Gravity = Gravity.RIGHT + Gravity.CENTER_VERTICAL
	lblSM.TextSize = FontSizeSM
	'lblSM.Color = FontColorSM
	lblSM.TextColor = FontColorSM
	lblSM.Tag = AField
	
	pnlQT.AddView(lblSM,iLblLeftL,ATop,iLblWidth,AHeight)
	
	Dim edtNR As EditText
	edtNR.Initialize("edtQTNR")
	edtNR.Text = ""
	edtNR.Hint = "--"
	edtNR.Gravity = AGravity
	edtNR.TextSize = FontSizeNR
	edtNR.Color = Colors.Black
	edtNR.TextColor = AColor
	
	edtNR.Tag = AField				

	Select ALX
		Case 0  '数字
			edtNR.InputType = edtNR.INPUT_TYPE_NUMBERS	
		Case 1  '数字
			edtNR.InputType = edtNR.INPUT_TYPE_DECIMAL_NUMBERS
		Case 2  '文字
			edtNR.InputType = edtNR.INPUT_TYPE_TEXT
			
	End Select

	pnlQT.AddView(edtNR,ALeft,ATop,AWidth,AHeight)		
End Sub

Sub btnTWNR_Click
	Dim btnTW As Button
	Dim iSel As Int
	btnTW = Sender
	iSel = TWLXList.IndexOf(btnTW.Text)
	If iSel<0 Then
		iSel = 0	
	End If
	iSel = InputList(TWLXList,"选择体温类型",iSel)
	If iSel>=0 Then 
		btnTW.Text = TWLXList.get(iSel) 
	End If
End Sub

Sub Refresh(ARQ As Long)
	Dim DataSetTW As Cursor
	Dim sSql As String
	Dim edtNR As EditText
	
	ClearAll
	
	'FLAG 1KB 2YB 3GB 4MB 5XL 6 HX
	sSql = "SELECT * FROM ZY_SCD1 WHERE BHID ="& V_BHID & " AND RQ="&ARQ & " ORDER BY FLAG"
	Log(sSql)
	DataSetTW = PublicVar.GV_SQLTool.ExecQuery(sSql)
	
	Dim TW(6) As Double
	Dim iFlag As Int
	For i = 0 To DataSetTW.RowCount - 1
		DataSetTW.Position = i
		
		TW(0) = DataSetTW.GetDouble("T1") 
		TW(1) = DataSetTW.GetDouble("T2") 
		TW(2) = DataSetTW.GetDouble("T3")
		TW(3) = DataSetTW.GetDouble("T4")
		TW(4) = DataSetTW.GetDouble("T5")
		TW(5) = DataSetTW.GetDouble("T6")
		
		iFlag = DataSetTW.GetInt("FLAG")
		FillTWData(TW,iFlag)
	Next
	
	DataSetTW.Close
	
	sSql = "SELECT * FROM ZY_SCD0 WHERE BHID ="& V_BHID & " AND RQ="&ARQ
	Log(sSql)
	DataSetTW = PublicVar.GV_SQLTool.ExecQuery(sSql)
	If DataSetTW.RowCount>0 Then
		DataSetTW.Position = 0	
	
		edtNR = GetXYEditText("SRYL")
		edtNR.Text = DataSetTW.GetInt("SRYL")
		
		edtNR = GetXYEditText("XY11")
		edtNR.Text = DataSetTW.GetInt("XY11")	
		
		edtNR = GetXYEditText("XY12")
		edtNR.Text = DataSetTW.GetInt("XY12")	
		
		edtNR = GetXYEditText("XY21")
		edtNR.Text = DataSetTW.GetInt("XY21")	
		
		edtNR = GetXYEditText("XY22")
		edtNR.Text = DataSetTW.GetInt("XY22")
		
		edtNR = GetXYEditText("DBCS")
		edtNR.Text = DataSetTW.GetString("DBCS")	
		
		edtNR = GetXYEditText("NL")
		edtNR.Text = DataSetTW.GetString("NL")	
		
		edtNR = GetXYEditText("PCLQT")
		edtNR.Text = DataSetTW.GetString("PCLQT")	
		
		'其他
		edtNR = GetQTEditText("PS")
		edtNR.Text = DataSetTW.GetString("PS")	
		
		edtNR = GetQTEditText("TZ")
		edtNR.Text = DataSetTW.GetString("TZ")
		
		edtNR = GetQTEditText("SG")
		edtNR.Text = DataSetTW.GetString("SG")	
		
		edtNR = GetQTEditText("QT")
		edtNR.Text = DataSetTW.GetString("QT")
		
		edtNR = GetQTEditText("CHRQ")
		edtNR.Text = DataSetTW.GetString("CHRQ")	
		
	End If

End Sub

Private Sub FillTWData(TW() As Double,FLAG As Int)
	Dim oView As View
	Dim btnNR As Button
	Dim edtNR As EditText
	Dim iXH As Int
	Dim fTW As Double
	Dim mapTag As Map
	Dim sField As String
	
	'FLAG 1KB 2YB 3GB 4MB 5XL 6 HX
	
	For i = 0 To pnlTW.NumberOfViews -1
		oView = pnlTW.GetView(i)
		If oView Is EditText Then
			edtNR = oView
			mapTag = edtNR.Tag
			sField = mapTag.get("Field")
			iXH = mapTag.get("XH") 
			fTW = TW(iXH-1)
			
			If (sField="TW" AND FLAG<=3) Then
				If fTW>0 Then
					edtNR.Text = fTW
					btnNR = getTWLXButton(iXH)
					btnNR.Text = TWLXList.Get(FLAG-1)
				End If
			
			Else If (sField="MB" AND FLAG=4) OR (sField="HX" AND FLAG=6) Then
				If fTW =0 Then
					edtNR.Text = ""	
				Else
					Dim iTW As Int
					iTW = fTW
					edtNR.Text = iTW				
				End If
			End If
			
		End If
	
	Next
	
End Sub

Private Sub ClearAll
	Dim oView As View
	Dim btnNR As Button
	Dim edtNR As EditText
	
  For i = pnlTW.NumberOfViews -1 To 0 Step -1
    oView = pnlTW.GetView(i) 
		If oView Is Button Then
			btnNR = oView
			btnNR.Text = TWLXList.Get(1)
		
		Else If oView Is EditText Then
			edtNR = oView
			edtNR.Text = ""
		
		End If
  Next
	
  For i = pnlXY.NumberOfViews -1 To 0 Step -1
    oView = pnlXY.GetView(i) 
		If oView Is EditText Then
			edtNR = oView
			edtNR.Text = ""
			
		End If
  Next
	
  For i = pnlQT.NumberOfViews -1 To 0 Step -1
    oView = pnlQT.GetView(i) 
		If oView Is EditText Then
			edtNR = oView
			edtNR.Text = ""
			
		End If
  Next
	
	
End Sub

'保存体温脉搏信息等
Private Sub SaveTWData(ARQ As Long) As Boolean
	Dim sSQL,sTWLX As String
	Dim TWKB(7),TWYB(7),TWGB(7),TWMB(7),TWHX(7) As Double
	
	For i = 0 To 6
		TWKB(i) = 0.0
		TWYB(i) = 0.0
		TWGB(i) = 0.0
		TWMB(i) = 0.0
		TWHX(i) = 0.0
	Next
	
	PublicVar.GV_SQLTool.BeginTransaction
	Try
		sSQL = "DELETE FROM ZY_SCD1 WHERE BHID ="& V_BHID & " AND RQ="& ARQ 
		Log("SQL: " & sSQL)
		PublicVar.GV_SQLTool.ExecNonQuery(sSQL)
		
		For i =1 To 6
			sTWLX = getTWLXText(i)
			Select TWLXList.IndexOf(sTWLX) 
				Case 0 'KB
					TWKB(i) = GetTWEditTextValue("TW",i)
					If TWKB(0)<1 AND TWKB(i)>0 Then TWKB(0) = 1
					
				Case 1 'YB
					TWYB(i) = GetTWEditTextValue("TW",i)
					If TWYB(0)<1 AND TWYB(i)>0 Then TWYB(0) = 1
					
				Case 2 'GB
					TWGB(i) = GetTWEditTextValue("TW",i)
					If TWGB(0)<1 AND TWGB(i)>0 Then TWGB(0) = 1
			End Select
			
			TWMB(i) = GetTWEditTextValue("MB",i)
			If TWMB(0)<1 AND TWMB(i)>0 Then TWMB(0) = 1
			
			TWHX(i) = GetTWEditTextValue("HX",i)
			If TWHX(0)<1 AND TWHX(i)>0 Then TWHX(0) = 1			
			
		Next

		'FLAG 1KB 2YB 3GB 4MB 5XL 6 HX
		'口表
		If TWKB(0) = 1 Then
			sSQL = "INSERT INTO ZY_SCD1(BHID,RQ,T1,T2,T3,T4,T5,T6,FLAG,_TB)"
			sSQL = sSQL & " VALUES("&V_BHID&","&ARQ&","&TWKB(1)&","&TWKB(2)&","&TWKB(3)
			sSQL = sSQL &","&TWKB(4)&","&TWKB(5)&","&TWKB(6)&",1,0)"
			Log("SQL: " & sSQL)
			PublicVar.GV_SQLTool.ExecNonQuery(sSQL)			
		End If

		'腋表
		If TWYB(0) = 1 Then
			sSQL = "INSERT INTO ZY_SCD1(BHID,RQ,T1,T2,T3,T4,T5,T6,FLAG,_TB)"
			sSQL = sSQL & " VALUES("&V_BHID&","&ARQ&","&TWYB(1)&","&TWYB(2)&","&TWYB(3)
			sSQL = sSQL &","&TWYB(4)&","&TWYB(5)&","&TWYB(6)&",2,0)"
			Log("SQL: " & sSQL)
			PublicVar.GV_SQLTool.ExecNonQuery(sSQL)			
		End If
		
		'肛表
		If TWGB(0) = 1 Then
			sSQL = "INSERT INTO ZY_SCD1(BHID,RQ,T1,T2,T3,T4,T5,T6,FLAG,_TB)"
			sSQL = sSQL & " VALUES("&V_BHID&","&ARQ&","&TWGB(1)&","&TWGB(2)&","&TWGB(3)
			sSQL = sSQL &","&TWGB(4)&","&TWGB(5)&","&TWGB(6)&",3,0)"
			Log("SQL: " & sSQL)
			PublicVar.GV_SQLTool.ExecNonQuery(sSQL)			
		End If	
		
		'脉搏
		If TWMB(0) = 1 Then
			sSQL = "INSERT INTO ZY_SCD1(BHID,RQ,T1,T2,T3,T4,T5,T6,FLAG,_TB)"
			sSQL = sSQL & " VALUES("&V_BHID&","&ARQ&","&TWMB(1)&","&TWMB(2)&","&TWMB(3)
			sSQL = sSQL &","&TWMB(4)&","&TWMB(5)&","&TWMB(6)&",4,0)"
			Log("SQL: " & sSQL)
			PublicVar.GV_SQLTool.ExecNonQuery(sSQL)			
		End If
		
		'呼吸
		If TWHX(0) = 1 Then
			sSQL = "INSERT INTO ZY_SCD1(BHID,RQ,T1,T2,T3,T4,T5,T6,FLAG,_TB)"
			sSQL = sSQL & " VALUES("&V_BHID&","&ARQ&","&TWHX(1)&","&TWHX(2)&","&TWHX(3)
			sSQL = sSQL &","&TWHX(4)&","&TWHX(5)&","&TWHX(6)&",6,0)"
			Log("SQL: " & sSQL)
			PublicVar.GV_SQLTool.ExecNonQuery(sSQL)			
		End If		
		
		PublicVar.GV_SQLTool.TransactionSuccessful
		
	Catch
		Log(LastException.Message)
		ToastMessageShow("保存失败"&CRLF&LastException.Message, True)	
		Return False	
	End Try
	PublicVar.GV_SQLTool.EndTransaction
	Return True
End Sub

Private Sub SaveXYData(ARQ As Long) As Boolean
	Dim sSQL As String
	Dim iSRYL,iDBCS As Int
	Dim fXY11,fXY12,fXY21,fXY22,fNL As Double
	Dim sPCLQT,sPS,sTZ,sSG,sQT,sCHRQ As String
	
	iSRYL = GetXYEditTextValue("SRYL")
	iDBCS = GetXYEditTextValue("DBCS")
	
	fXY11 = GetXYEditTextValue("XY11")
	fXY12 = GetXYEditTextValue("XY21")
	fXY21 = GetXYEditTextValue("XY12")
	fXY22 = GetXYEditTextValue("XY22")
	fNL = GetXYEditTextValue("NL")
	sPCLQT = GetXYEditTextValue("PCLQT")

	sPS = GetQTEditTextValue("PS")
	sTZ = GetQTEditTextValue("TZ")
	sSG = GetQTEditTextValue("SG")
	sQT = GetQTEditTextValue("QT")	
	sCHRQ = GetQTEditTextValue("CHRQ")
	
	PublicVar.GV_SQLTool.BeginTransaction
	Try
		sSQL = "DELETE FROM ZY_SCD0 WHERE BHID ="& V_BHID & " AND RQ="& ARQ 
		Log("SQL: " & sSQL)
		PublicVar.GV_SQLTool.ExecNonQuery(sSQL)
		
		'
		sSQL = "INSERT INTO ZY_SCD0(BHID,RQ,SRYL,XY11,XY12,XY21,XY22,DBCS,NL,PCLQT,PS,TZ,SG,QT,CHRQ,_TB)"
		sSQL = sSQL & " VALUES("&V_BHID&","&ARQ&","&iSRYL&","&fXY11&","&fXY12
		sSQL = sSQL &","&fXY21&","&fXY22&","&iDBCS&","&fNL&",'"&sPCLQT&"','"&sPS&"','"&sTZ&"','"&sSG&"','"&sQT&"','"&sCHRQ&"',0)"
		Log("SQL: " & sSQL)
		PublicVar.GV_SQLTool.ExecNonQuery(sSQL)				
		
		PublicVar.GV_SQLTool.TransactionSuccessful
	Catch
		Log(LastException.Message)
		ToastMessageShow("保存失败"&CRLF&LastException.Message, True)	
		Return False	
	End Try
	PublicVar.GV_SQLTool.EndTransaction	

	Return True
End Sub
Sub btnOK_Click
	Dim bTW,bBH As Boolean
	
	bTW = SaveTWData(V_RQ)
	bBH = SaveXYData(V_RQ)
	
	If bTW AND bBH Then
		ToastMessageShow("保存成功",True)	
	End If

End Sub

Sub btnSearch_Click
	
End Sub
Sub btnCancel_Click
	
End Sub

Private Sub getTWLXButton(AXH As Int) As Button
	Dim oView As View
	Dim btnNR,btnRE As Button
	Dim iXH As Int
	Dim mapTag As Map
	Dim sField As String
	
  For i = pnlTW.NumberOfViews -1 To 0 Step -1
    oView = pnlTW.GetView(i) 
		If oView Is Button Then
			btnNR = oView
			mapTag = btnNR.Tag
			sField = mapTag.get("Field")
			iXH = mapTag.get("XH")
			
			If sField = "TWLX" AND AXH = iXH Then
				btnRE = btnNR
				Exit
			End If
		
		End If
  Next	
	
	Return btnRE

End Sub

Private Sub getTWLXText(AXH As Int) As String
	Dim btnNR As Button
	
	btnNR = getTWLXButton(AXH)
	Return btnNR.Text
	
End Sub

Private Sub GetTWEditText(AField As String,AXH As Int) As EditText
	Dim oView As View
	Dim edtNR As EditText
	Dim iXH As Int
	Dim mapTag As Map
	Dim sField As String
	Dim sRet As EditText
	
  For i = pnlTW.NumberOfViews -1 To 0 Step -1
    oView = pnlTW.GetView(i) 
		If oView Is EditText Then
			edtNR = oView
			mapTag = edtNR.Tag
			sField = mapTag.get("Field")
			iXH = mapTag.get("XH")
			
			If sField = AField AND AXH = iXH Then
				sRet = edtNR
				Exit
			End If
		
		End If
  Next

	Return sRet
End Sub

Sub GetTWEditTextValue(AField As String,AXH As Int) As Double
	Dim edtNR As EditText
	edtNR = GetTWEditText(AField,AXH)
	If edtNR<>Null AND IsNumber(edtNR.Text) Then
		Return edtNR.Text
	Else
		Return 0.0
	End If

End Sub

Private Sub GetXYEditText(AField As String) As EditText
	Dim oView As View
	Dim edtNR As EditText
	Dim sRet As EditText
	
  For i = pnlXY.NumberOfViews -1 To 0 Step -1
    oView = pnlXY.GetView(i) 
		If oView Is EditText Then
			edtNR = oView
		
			If edtNR.Tag = AField Then
				sRet = edtNR
				Exit
			End If
		
		End If
  Next

	Return sRet
End Sub

Sub GetXYEditTextValue(AField As String) As String
	Dim edtNR As EditText
	edtNR = GetXYEditText(AField)
	
	Select edtNR.InputType
		Case edtNR.INPUT_TYPE_NUMBERS,edtNR.INPUT_TYPE_DECIMAL_NUMBERS  '数字
			If IsNumber(edtNR.Text) Then
				Return edtNR.Text
			Else
				Return "0"
			End If
				
		Case Else 
			Return edtNR.Text	
			
	End Select	

End Sub

Private Sub GetQTEditText(AField As String) As EditText
	Dim oView As View
	Dim edtNR As EditText
	Dim sRet As EditText
	
  For i = pnlQT.NumberOfViews -1 To 0 Step -1
    oView = pnlQT.GetView(i) 
		If oView Is EditText Then
			edtNR = oView
		
			If edtNR.Tag = AField Then
				sRet = edtNR
				Exit
			End If
		
		End If
  Next

	Return sRet
End Sub

Sub GetQTEditTextValue(AField As String) As String
	Dim edtNR As EditText
	edtNR = GetQTEditText(AField)
	
	Select edtNR.InputType
		Case edtNR.INPUT_TYPE_NUMBERS,edtNR.INPUT_TYPE_DECIMAL_NUMBERS  '数字
			If IsNumber(edtNR.Text) Then
				Return edtNR.Text
			Else
				Return "0"
			End If
				
		Case Else 
			Return edtNR.Text	
			
	End Select	

End Sub

